<!--#
layout("/layouts/platform.html"){
#-->
<div id="app" v-cloak>
    <el-row class="header navbar shadow">
        <div class="btn-group tool-button mt5">
            <el-input placeholder="请输入流水号" v-model="pageForm.no" @keyup.enter.native="pageData"></el-input>
        </div>
        <div class="btn-group tool-button mt5">
            <el-input placeholder="请输入转出人手机号、昵称或用户名" v-model="pageForm.transferKeyword"
                      @keyup.enter.native="pageData"></el-input>
        </div>
        <div class="btn-group tool-button mt5">
            <el-input placeholder="请输入收款人手机号、昵称或用户名" v-model="pageForm.collectKeyword"
                      @keyup.enter.native="pageData"></el-input>
        </div>
        <!--时间-->
        <div class="btn-group tool-button mt5">
            <el-date-picker
                    v-model="searchDate"
                    type="datetimerange"
                    :picker-options="pickerOptions"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期"
                    align="right"
                    size="medium"
                    :default-time="['00:00:00', '23:59:59']"
                    value-format="yyyy-MM-dd HH:mm:ss">
            </el-date-picker>
        </div>
        <!--下拉框-->
        <div class="btn-group tool-button mt5">
            <el-select v-model="pageForm.status" placeholder="请选择状态"
                       size="medium" style="width: 120px">
                <el-option
                        v-for="item in statusData"
                        :key="item.val"
                        :label="item.name"
                        :value="item.val"
                >
                </el-option>
            </el-select>
        </div>
        <!--搜索按钮-->
        <div class="btn-group tool-button mt5">
            <el-button slot="append" icon="el-icon-search" @click="doSearch" size="medium"></el-button>
        </div>
    </el-row>
    <el-row class="el-table-container">
        <el-table
                :data="tableData"
                @sort-change='pageOrder'
                size="small"
                header-align="center"
                style="width: 100%">
            <!--流水号-->
            <el-table-column
                    label="流水号"
                    prop="no"
                    header-align="center"
                    :show-overflow-tooltip="true"
                    align="center">
            </el-table-column>
            <!--划转用户名-->
            <el-table-column
                    label="划转用户名"
                    prop="transferUserName"
                    header-align="center"
                    :show-overflow-tooltip="true"
                    align="center">
            </el-table-column>
            <!--划转用户昵称-->
            <el-table-column
                    label="划转用户昵称"
                    prop="transferNickName"
                    header-align="center"
                    :show-overflow-tooltip="true"
                    align="center">
            </el-table-column>
            <!--划转用户手机号-->
            <el-table-column
                    label="划转用户手机号"
                    prop="transferPhone"
                    header-align="center"
                    :show-overflow-tooltip="true"
                    align="center">
            </el-table-column>
            <!--划转金额-->
            <el-table-column
                    label="划转数量"
                    prop="amount"
                    header-align="center"
                    :show-overflow-tooltip="true"
                    align="center">
            </el-table-column>
            <!--收款用户名-->
            <el-table-column
                    label="收款用户名"
                    prop="collectUserName"
                    header-align="center"
                    :show-overflow-tooltip="true"
                    align="center">
            </el-table-column>
            <!--收款用户昵称-->
            <el-table-column
                    label="收款用户昵称"
                    prop="collectNickName"
                    header-align="center"
                    :show-overflow-tooltip="true"
                    align="center">
            </el-table-column>
            <!--收款用户手机号-->
            <el-table-column
                    label="收款用户手机号"
                    prop="collectPhone"
                    header-align="center"
                    :show-overflow-tooltip="true"
                    align="center">
            </el-table-column>
            <!--状态-->
            <el-table-column
                    label="状态"
                    prop="status"
                    header-align="center"
                    :show-overflow-tooltip="true"
                    align="center">
                <template slot-scope="scope">
                    {{getStatusName(scope.row.status)}}
                </template>
            </el-table-column>
            <!--创建时间-->
            <el-table-column
                    prop="ctAt"
                    label="创建时间"
                    header-align="center"
                    align="center"
                    width="120px">
                <template slot-scope="scope">
                    {{formatAt(scope.row.ctAt)}}
                </template>
            </el-table-column>
            <!--操作时间-->
            <el-table-column
                    prop="opAt"
                    label="操作时间"
                    header-align="center"
                    align="center"
                    width="120px">
                <template slot-scope="scope">
                    {{formatAt(scope.row.opAt)}}
                </template>
            </el-table-column>
        </el-table>
    </el-row>
    <el-row class="el-pagination-container">
        <el-pagination
                @size-change="pageSizeChange"
                @current-change="pageNumberChange"
                :current-page="pageForm.pageNumber"
                :page-sizes="[10, 20, 30, 50]"
                :page-size="pageForm.pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="pageForm.totalCount">
        </el-pagination>
    </el-row>
</div>
<script>
    new Vue({
        el: "#app",
        data: function () {
            return {
                pickerOptions: {
                    disabledDate: function (time) {
                        var threeMonths = moment().add(-3, 'months').valueOf();
                        return time.getTime() > new Date(new Date(new Date().toLocaleDateString()).getTime() + 24 * 60 * 60 * 1000 - 1)
                            || time.getTime() < threeMonths;
                    },
                    shortcuts: [{
                        text: '最近一周',
                        onClick: function (picker) {
                            var end = new Date();
                            var start = new Date();
                            var temp = moment().add(-1, 'weeks').valueOf();
                            start.setTime(temp);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近一个月',
                        onClick: function (picker) {
                            var end = new Date();
                            var start = new Date();
                            var temp = moment().add(-1, 'months').valueOf();
                            start.setTime(temp);
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近三个月',
                        onClick: function (picker) {
                            var end = new Date();
                            var start = new Date();
                            var temp = moment().add(-3, 'months').valueOf();
                            start.setTime(temp);
                            picker.$emit('pick', [start, end]);
                        }
                    }]
                },
                selectData: [],
                statusData: [],
                searchDate: [],
                pageForm: {
                    pageNumber: 1,
                    pageSize: 10
                },
                tableData: [],
                loading: false,
                showRestriction: false
            }
        },
        methods: {
            getStatusName: function (val) {
                for (let statusKey in this.statusData) {
                    if (this.statusData[statusKey].val === val) {
                        return this.statusData[statusKey].name;
                    }
                }
            },
            pageOrder: function (column) {//按字段排序
                this.pageForm.pageOrderName = column.prop;
                this.pageForm.pageOrderBy = column.order;
                this.pageData();
            },
            pageNumberChange: function (val) {//页码更新操作
                this.pageForm.pageNumber = val;
                this.pageData();
            },
            pageSizeChange: function (val) {//分页大小更新操作
                this.pageForm.pageSize = val;
                this.pageData();
            },
            doSearch: function () {
                this.pageForm.pageNumber = 1;
                this.pageData();
            },
            pageData: function () {//加载分页数据
                var self = this;
                sublime.showLoadingbar();//显示loading
                $.post(base + "/platform/user/account/transfer/list", self.pageForm, function (data) {
                    sublime.closeLoadingbar();//关闭loading
                    if (data.code === 0) {
                        self.tableData = data.data.list;
                        self.pageForm.totalCount = data.data.totalCount;
                    } else {
                        self.$message({
                            message: data.msg,
                            type: 'error'
                        });
                    }
                }, "json");
            },
            formatAt: function (val) {
                if (val > 0)
                    return moment(val * 1000).format("YYYY-MM-DD HH:mm");
                return "";
            },
            handleSelectionChange: function (val) {
                this.selectData = val;
            },
            getStatusList: function () {
                let self = this;
                $.post(base + "/platform/user/account/transfer/getTransferStatusList", function (data) {
                    if (data.code === 0) {
                        self.statusData = data.data;
                        self.statusData.unshift({
                            name: '全部状态',
                            val: ''
                        });
                    } else {
                        self.$message({
                            message: data.msg,
                            type: 'error'
                        });
                    }
                }, "json");
            }
        },
        created: function () {
            this.getStatusList();
            this.pageData();
        }
    });
</script>
<!--#
}
#-->